<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    
    <title>MongoDB | 王鹏的技术博客</title>
    
    
        <meta property="og:site_name" content="王鹏的技术博客">
    
    
        <meta property="article:author" content="王 鹏">
    
    
        <link rel="icon" href="/mhexo/img/favicon.ico">
    
    
<link rel="stylesheet" href="/mhexo/css/minireset.min.css">

    
<link rel="stylesheet" href="/mhexo/css/all.min.css">

    
<link rel="stylesheet" href="/mhexo/css/csshake.min.css">

    
<link rel="stylesheet" href="/mhexo/css/hljs/lioshi.css">

    
<link rel="stylesheet" href="/mhexo/css/jquery.fancybox.min.css">

    
<link rel="stylesheet" href="/mhexo/styl/main.css">

    
<script src="/mhexo/js/jquery.min.js"></script>

    
<script src="/mhexo/js/highlight.min.js"></script>

    
<script src="/mhexo/js/jquery.fancybox.min.js"></script>

    
<script src="/mhexo/js/clipboard.min.js"></script>

<meta name="generator" content="Hexo 5.2.0"></head>
<body>
    <header>
  <div class="outer">
    <div class="inner">
      <h1 class="logo-wrap">
        <a>王鹏的技术博客<b><sup>1.1</sup></b></a>
      </h1>
    </div>
    <div class="inner">
      <nav class="main-nav">
        
          <a href="/mhexo/">首页</a>
        
          <a href="/mhexo/archives">归档</a>
        
          <a href="/mhexo/categories">分类</a>
        
          <a href="/mhexo/tags">标签</a>
        
          <a href="/mhexo/friends">友链</a>
        
          <a href="/mhexo/about">关于</a>
        
          <a target="_blank" rel="noopener" href="https://www.baidu.com">百度</a>
        
      </nav>
    </div>
  </div>
</header>
    <div class="content">
        <section class="outer">
    <article>
        <div class="article-title">
    <h2>
        <a href="/mhexo/2020/12/19/MongoDB/" class="shake shake-little" title="MongoDB">
            
            MongoDB
        </a>
    </h2>
    <div class="meta_box">
    
        
        
            
                
        
        <div class="meta meta_auth">
            <img src="/mhexo/img/default.png" alt="head" />
            <p>anonymous</p>
        </div>
    
        
        
        <div class="meta meta_date">
            <i class="fas fa-calendar-alt fa-fw" aria-hidden="true"></i>
            <p>发布于：2020年12月19日</p>
        </div>
    
        <div class="meta meta_update">
            <i class="fas fa-edit fa-fw" aria-hidden="true"></i>
            <p>更新于：2020年12月19日</p>
        </div>
    </div>
    

</div>

        <hr>
        <div class="article-entry">
            
            
            
            <h1 id="01：MongoDB基础"><a href="#01：MongoDB基础" class="headerlink" title="     01：MongoDB基础        "></a><a target="_blank" rel="noopener" href="https://www.cnblogs.com/xiaonq/p/10356568.html">     01：MongoDB基础        </a></h1><h3 id="1-1-MongoDB简介"><a href="#1-1-MongoDB简介" class="headerlink" title="1.1 MongoDB简介"></a>1.1 MongoDB简介</h3><p>　　<strong>1、特点</strong></p>
<p>　　　　　　1. MongoDB的提供了一个面向文档存储，操作起来比较简单和容易。</p>
<p>　　　　　　2. 你可以在MongoDB记录中设置任何属性的索引 (如：FirstName=”Ning”,Address=”Beijing”)来实现更快的排序。</p>
<p>　　　　　　3. 你可以通过本地或者网络创建数据镜像，这使得MongoDB有更强的扩展性。</p>
<p>　　　　　　4. 如果负载的增加（需要更多的存储空间和更强的处理能力） ，它可以分布在计算机网络中的其他节点上这就是所谓的分片。</p>
<p>　　　　　　5. Mongo支持丰富的查询表达式。查询指令使用JSON形式的标记，可轻易查询文档中内嵌的对象及数组。</p>
<p>　　　　　　6. MongoDb 使用update()命令可以实现替换完成的文档（数据）或者一些指定的数据字段 。</p>
<p>　　　　　　7. Mongodb中的Map/reduce主要是用来对数据进行批量处理和聚合操作。</p>
<p>　　　　　　8. Map和Reduce。Map函数调用emit(key,value)遍历集合中所有的记录，将key与value传给Reduce函数进行处理。</p>
<p>　　　　　　9. Map函数和Reduce函数是使用Javascript编写的，并可以通过db.runCommand或mapreduce命令来执行MapReduce操作。</p>
<p>　　　　　　10. GridFS是MongoDB中的一个内置功能，可以用于存放大量小文件。</p>
<p>　　　　　　11. MongoDB允许在服务端执行脚本，可以用Javascript编写某个函数，直接在服务端执行，也可以把函数的定义存储在服务端，下次直接调用即可。</p>
<p>　　　　　　12. MongoDB支持各种编程语言:RUBY，PYTHON，JAVA，C++，PHP，C#等多种语言。</p>
<p>　　<strong>2、MongoDB简介</strong></p>
<p>　　　　　　1. MongoDB是一个文档型的NoSQL数据库，文档型—&gt; BSON文档（json的二进制）<br>　　　　　　2. 保存数据：key-value<br>　　　　　　3. 一般不支持事务</p>
<p>　　<strong>3、MongoDB使用场景</strong></p>
<p>　　　　<strong>1）更高的写入负载</strong></p>
<p>　　　　　　　　默认情况下，MongoDB更侧重高数据写入性能，而非事务安全，MongoDB很适合业务系统中有大量“低价值”数据的场景。</p>
<p>　　　　　　　　但是应当避免在高事务安全性的系统中使用MongoDB，除非能从架构设计上保证事务安全。</p>
<p>　　　　<strong>2）高可用性</strong></p>
<p>　　　　　　　　MongoDB的复副集(Master-Slave)配置非常简洁方便，此外，MongoDB可以快速响应的处理单节点故障，自动、安全的完成故障转移。</p>
<p>　　　　　　　　这些特性使得MongoDB能在一个相对不稳定（如云主机）的环境中，保持高可用性。</p>
<p>　　　　<strong>3）表结构不明确，且数据在不断变大</strong></p>
<p>　　<strong>4、MongoDB应用举例</strong></p>
<p>　　　　　　1. 比如豆瓣影评中有1000部电影，每部电影有1000个影评，每个影评有1000个评论，那么查询笛卡尔积是1000<em>1000</em>1000</p>
<p>　　　　　　2. 而使用MongoDB只需要存储1000条数据即可完成上述数据查询</p>
<p>　　　　　　<img src="https://img2018.cnblogs.com/blog/1080958/201902/1080958-20190209143451787-1190789126.png" alt="img"></p>
<h3 id="1-2-MongoDB安装与配置"><a href="#1-2-MongoDB安装与配置" class="headerlink" title="1.2 MongoDB安装与配置"></a>1.2 MongoDB安装与配置</h3><p>　　<strong>1、上传解压安装MongoDB</strong></p>
<p>　　　　　　mkdir tools # 存放安装包<br>　　　　　　mkdir training            # 存放安装目录</p>
<p>　　　　　　tar -zxvf mongodb-linux-x86_64-enterprise-rhel70-3.4.10.tgz -C ~/training/</p>
<p>　　　　　　vi ~/.bash_profile</p>
<p><img src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="img"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">MONGODB_HOME&#x3D;&#x2F;root&#x2F;training&#x2F;mongodb-linux-x86_64-enterprise-rhel70-3.4.10</span><br><span class="line">export MONGODB_HOME</span><br><span class="line"></span><br><span class="line">PATH&#x3D;$MONGODB_HOME&#x2F;bin:$PATH</span><br><span class="line">export PATH</span><br></pre></td></tr></table></figure>



<p>　　　　　　source ~/.bash_profile        # 生效环境变量, 使在任何位置都可以使用MongoDB命令</p>
<p>　　　　　　<strong>安装MongoDB依赖rpm包</strong></p>
<p>　　　　　　yum install -y net-snmp*       # 安装net-snmp :<br>　　　　　　yum install -y cyrus*          # 安装cyrus : </p>
<p>　　　　　　<strong>启动MongoDB</strong></p>
<p>　　　　　　mkdir -p /data/db</p>
<p>　　　　　　mongod –dbpath /data/db     # 指定MongoDB数据库文件存储路径（从3.2版本后，MongoDB的默认的数据引擎：wiredTiger）</p>
<p>　　　　　　mongod –dbpath /data/db1 –storageEngine=mmapv1     # 早期：内存映射，可以指定参数 –storageEngine=mmapv1</p>
<p>　　　　　　<strong>使用MongoDB Web的控制台：需要在启动MongoDB的时候，指定参数: –httpinterface</strong></p>
<p>　　　　　　mongod –dbpath /data/db1 –storageEngine=mmapv1 –httpinterface   </p>
<p>　　<strong>2、测试MongoDB shell</strong></p>
<p>　　　　　　mongo           # 进入mongo shell环境</p>
<p>　　　　　　show dbs         # 查看所有db</p>
<p>　　　　　　use mydemo      # 使用我们的数据库（如果没有这个数据库会自动创建）</p>
<p>　　　　　　db.test1.insert({id:1,”name”:”Tom”})         # 在test1表中插入一条数据（如果没有这个表会自动创建）</p>
<h3 id="1-3-MongoDB的体系结构"><a href="#1-3-MongoDB的体系结构" class="headerlink" title="1.3 MongoDB的体系结构"></a>1.3 MongoDB的体系结构</h3><p>　　<strong>1、一个MongoDB Server：实例和多个数据库（1：N）</strong></p>
<p> 　　　　　<img src="https://img2018.cnblogs.com/blog/1080958/201902/1080958-20190209154845888-2091444.png" alt="img"></p>
<p>　　<strong>2、逻辑存储结构</strong></p>
<p> 　　　　　数据库（database）、表（集合Collection）、记录（文档Document）</p>
<p>　　<strong>3、物理存储结构</strong></p>
<p>　　　　1）–dbpath /data/db 指定数据库文件存储的位置</p>
<p>　　　　2）MongoDB的物理存储的文件<br>                    　　　　　　（<em>）命名空间文件：  后缀： .ns  大小   16M<br>                    　　　　　　（</em>）数据文件： 后缀：0,1,2,3****<br>                                    　　　　　　　　大小： 0 —&gt; 16M<br>                                           　　　　　　　　　　　 1 —&gt; 32M<br>                                           　　　　　　　　　　 　2 —&gt; 64M<br>　　　　　　（*）日志文件：存储的位置可能不一样<br>                            　　　　　　　　（1）直接存储在操作系统<br>                                 　　　　　　　　　　　　系统日志文件：  记录的是系统的启动信息、告警信息等等<br>                                 　　　　　　　　　　　　journal日志文件：重做日志，即：redo日志，用于恢复<br>                            　　　　　　　　（2）存储在集合中（Collection）中<br>                                 　　　　　　　　　　　　oplog： 复制操作的日志（只在：主从复制的功能）<br>                                 　　　　　　　　　　　　慢查询的日志（需要单独配置）：一般在生产系统中：大于200毫秒的日志</p>
<p> 　　　　注意：从3.2版本后，MongoDB的默认的数据引擎：wiredTiger<br>              　　　　早期：内存映射，可以指定参数  –storageEngine=mmapv1<br>              　　　　新版本：数据文件大小从：64M开始</p>
<h3 id="1-4-使用mongo-shell"><a href="#1-4-使用mongo-shell" class="headerlink" title="1.4 使用mongo shell"></a>1.4 使用mongo shell</h3><p>　　<strong>1、启动mongo shell</strong><br>        　　　　　　mongo         # 直接输入mongo即可进入mongo shell环境</p>
<p>　　　　　　mongo -u <strong>* -p *</strong> -host <strong>* -port *</strong></p>
<p>​        　　　　　　<strong>参数:</strong> </p>
<p>　　　　　　　　–username 用户名<br>　　　　　　　　–password 密码<br>　　　　　　　　–host<br>　　　　　　　　–port</p>
<p>　　<strong>2、可以在mongo Shell使用外部的编辑器：vi</strong></p>
<p>　　　　　　[root@linux-node2 db]#  <strong>export EDITOR=vi</strong>            # 定义环境变量 后需要重新进入mongo shell环境中<br>　　　　　　[root@linux-node2 db]#  <strong>mongo</strong>　　　　　</p>
<p>　　　　　　MongoDB Enterprise &gt;  <strong>function myFunction(){}</strong><br>　　　　　　MongoDB Enterprise &gt;  <strong>edit myFunction   # 修改myFunction函数</strong></p>
<p>　　　　　　function myFunction(){print(“hello word”)}<br>　　　　　　MongoDB Enterprise &gt;  <strong>myFunction()     # 运行myFunction() 函数</strong><br>　　　　　　hello word</p>
<p>　　<strong>3、使用启动配置文件</strong></p>
<p>　　　　　　vim ~/.mongorc.js</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">host=db.serverStatus().host;</span><br><span class="line">cmdCount=<span class="number">1</span>;	</span><br><span class="line">prompt=function()&#123;</span><br><span class="line">   <span class="keyword">return</span> db+<span class="string">&quot;@&quot;</span>+host+<span class="string">&quot; &quot;</span>+(cmdCount++) +<span class="string">&quot;&gt;&quot;</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27; 此时的mongo shell就会显示 数据库名（test）主机名（linux-node2.example.com）  条数</span></span><br><span class="line"><span class="string">test@linux-node2.example.com 1&gt;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br></pre></td></tr></table></figure>





<p>　　<strong>4、mongo shell的基本操作</strong></p>
<p>　　　　　　show dbs            # 查看所有数据库</p>
<p>　　　　　　use mydemo1        # 使用数据库（如果没有当前数据库会自动创建）</p>
<p>　　　　　　show tables          # 查看当前数据库所有表</p>
<p>　　　　　　show collections       # 查看当前集合</p>
<h3 id="1-5-MongoDB数据类型"><a href="#1-5-MongoDB数据类型" class="headerlink" title="1.5 MongoDB数据类型"></a>1.5 MongoDB数据类型</h3><p>　　 <strong>注：</strong>mongo shell数据类型：字符串、整型、布尔值、浮点数、时间 <strong>**</strong></p>
<p>　　<strong>1、日期类型：date</strong></p>
<p> 　　　　　　使用不同方式来创建一个date<br>                　　　　　　(<em>) Date():表示当前时间，插入的是一个字符串类型<br>                　　　　　　(</em>) new Date():插入的是isodate类型，表示的是格林威治标准时间<br>                　　　　　　(*) ISODate(): 类似new Date()</p>
<p>　　<strong>2、ObjectId:</strong> </p>
<p>　　　　　　当插入数据的时候，自动生成一个字段: _id —&gt; 相当于主键<br>                       　　　　　　ObjectId是一个12字节的BSON类型的字符串</p>
<p>　　<strong>3、表示数字的时候，注意的问题</strong><br>            　　　　　　NumberInt: 表示32位整数<br>            　　　　　　NumberDecimal:支持34位小数<br>            　　　　　　Double：如果没有指定数字类型默认是double</p>
<p>　　<strong>4、测试</strong></p>
<p><img src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="img"></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">db.test2.insertOne(&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">1</span>, <span class="string">&quot;val&quot;</span> : NumberDecimal( <span class="string">&quot;9.99&quot;</span> ), <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Decimal&quot;</span> &#125;)</span><br><span class="line">db.test2.insertOne(&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">2</span>, <span class="string">&quot;val&quot;</span> : <span class="number">9.99</span>, <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Double&quot;</span> &#125;)</span><br><span class="line">db.test2.insertOne(&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">3</span>, <span class="string">&quot;val&quot;</span> : <span class="number">10</span>, <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Double&quot;</span> &#125;)</span><br><span class="line">db.test2.insertOne(&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">4</span>, <span class="string">&quot;val&quot;</span> : NumberLong(<span class="number">10</span>), <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Long&quot;</span> &#125;)</span><br><span class="line">db.test2.insertOne(&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">5</span>, <span class="string">&quot;val&quot;</span> : NumberDecimal( <span class="string">&quot;10.0&quot;</span> ), <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Decimal&quot;</span> &#125;)</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">**<span class="number">1</span>、查询表中所有数据**</span><br><span class="line">db.test2.find()</span><br><span class="line"></span><br><span class="line">​```</span><br><span class="line"></span><br><span class="line">​```</span><br><span class="line"></span><br><span class="line">**<span class="number">2</span>、数字不指定数据类型时默认是double类型，所以只能查到一条**</span><br><span class="line">db.test2.find(&#123;<span class="string">&quot;val&quot;</span>:<span class="number">9.99</span>&#125;)</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">2</span>, <span class="string">&quot;val&quot;</span> : <span class="number">9.99</span>, <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Double&quot;</span> &#125;</span><br><span class="line"></span><br><span class="line">​```</span><br><span class="line"></span><br><span class="line">​```</span><br><span class="line"></span><br><span class="line">**<span class="number">3</span>、类型为NumberDecimal，值为<span class="number">9.99</span>的数据**</span><br><span class="line">db.test2.find(&#123;<span class="string">&quot;val&quot;</span>:NumberDecimal(<span class="string">&quot;9.99&quot;</span>)&#125;)</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">1</span>, <span class="string">&quot;val&quot;</span> : NumberDecimal(<span class="string">&quot;9.99&quot;</span>), <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Decimal&quot;</span> &#125;</span><br><span class="line"></span><br><span class="line">​```</span><br><span class="line"></span><br><span class="line">​```</span><br><span class="line"></span><br><span class="line">**<span class="number">4</span>、对于整数<span class="number">10</span>的匹配，将匹配所有的数据类型是<span class="number">10</span>**</span><br><span class="line">db.test2.find(&#123;<span class="string">&quot;val&quot;</span>:<span class="number">10</span>&#125;)</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">3</span>, <span class="string">&quot;val&quot;</span> : <span class="number">10</span>, <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Double&quot;</span> &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">4</span>, <span class="string">&quot;val&quot;</span> : NumberLong(<span class="number">10</span>), <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Long&quot;</span> &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">5</span>, <span class="string">&quot;val&quot;</span> : NumberDecimal(<span class="string">&quot;10.0&quot;</span>), <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Decimal&quot;</span> &#125;</span><br><span class="line">	</span><br><span class="line"><span class="number">5</span>、db.test2.find(&#123;<span class="string">&quot;val&quot;</span>:NumberDecimal(<span class="string">&quot;10&quot;</span>)&#125;)</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">3</span>, <span class="string">&quot;val&quot;</span> : <span class="number">10</span>, <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Double&quot;</span> &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">4</span>, <span class="string">&quot;val&quot;</span> : NumberLong(<span class="number">10</span>), <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Long&quot;</span> &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : <span class="number">5</span>, <span class="string">&quot;val&quot;</span> : NumberDecimal(<span class="string">&quot;10.0&quot;</span>), <span class="string">&quot;description&quot;</span> : <span class="string">&quot;Decimal&quot;</span> &#125;</span><br></pre></td></tr></table></figure>

<h1 id="02：MongoDB操作"><a href="#02：MongoDB操作" class="headerlink" title="     02：MongoDB操作        "></a><a target="_blank" rel="noopener" href="https://www.cnblogs.com/xiaonq/p/10358669.html">     02：MongoDB操作        </a></h1><h3 id="1-1-MongoDB-增加"><a href="#1-1-MongoDB-增加" class="headerlink" title="1.1 MongoDB 增加"></a>1.1 MongoDB 增加</h3><p>　　<strong>1、插入数据</strong></p>
<p>　　　　　　1. 插入文档: insert 如果插入数据的时候，collection还不存在，自动创建集合<br>        　　　　　　2. insertOne: 插入一条数据<br>        　　　　　　3. insertMany: 接收数组，插入多条文档</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1、插入单条数据</span></span><br><span class="line">db.student1.insertOne(&#123;_id:<span class="string">&quot;stu001&quot;</span>,<span class="string">&quot;name&quot;</span>:<span class="string">&quot;Tom&quot;</span>,<span class="string">&quot;age&quot;</span>:<span class="number">25</span>,grade:&#123;<span class="string">&quot;chinese&quot;</span>:<span class="number">80</span>,<span class="string">&quot;math&quot;</span>:<span class="number">90</span>,<span class="string">&quot;english&quot;</span>:<span class="number">88</span>&#125;&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">#2、插入多条数据</span></span><br><span class="line">db.student1.insertMany([</span><br><span class="line">&#123;_id:<span class="string">&quot;stu002&quot;</span>,<span class="string">&quot;name&quot;</span>:<span class="string">&quot;Mary&quot;</span>,<span class="string">&quot;age&quot;</span>:<span class="number">23</span>,grade:&#123;<span class="string">&quot;chinese&quot;</span>:<span class="number">80</span>,<span class="string">&quot;math&quot;</span>:<span class="number">90</span>&#125;&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu003&quot;</span>,<span class="string">&quot;name&quot;</span>:<span class="string">&quot;Mike&quot;</span>,<span class="string">&quot;age&quot;</span>:<span class="number">23</span>,grade:&#123;<span class="string">&quot;chinese&quot;</span>:<span class="number">81</span>,<span class="string">&quot;math&quot;</span>:<span class="number">90</span>,<span class="string">&quot;english&quot;</span>:<span class="number">88</span>&#125;&#125;</span><br><span class="line">]);</span><br></pre></td></tr></table></figure>

<p>　　<strong>2、更新文档: updateOne和updateMany</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1、更新_id=7839的薪水 ---&gt; 8000</span></span><br><span class="line">db.emp.updateOne(&#123;<span class="string">&quot;_id&quot;</span>:<span class="number">7839</span>&#125;,&#123;$<span class="built_in">set</span>:&#123;<span class="string">&quot;sal&quot;</span>:<span class="number">8000</span>&#125;&#125;)</span><br><span class="line">db.emp.find(&#123;<span class="string">&quot;_id&quot;</span>:<span class="number">7839</span>&#125;)  <span class="comment"># 查询id=7893的文档</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#2、更新多条数据：更新10号部门的员工薪水，加100块钱</span></span><br><span class="line">错误：db.emp.updateMany(&#123;&quot;deptno&quot;:&#123;$eq:10&#125;&#125;,&#123;$set:&#123;&quot;sal&quot;:&quot;sal&quot;+100&#125;&#125;)  ---&gt; 不对</span><br><span class="line">正确：db.emp.updateMany(&#123;<span class="string">&quot;deptno&quot;</span>:&#123;$eq:<span class="number">10</span>&#125;&#125;,&#123;$inc:&#123;<span class="string">&quot;sal&quot;</span>,<span class="number">100</span>&#125;&#125;)</span><br></pre></td></tr></table></figure>

<p>　　<strong>3、删除文档: deleteOne和deleteMany</strong></p>
<p>　　　　　　db.emp.deleteOne({“_id”:7839})</p>
<p>　　<strong>4、批处理</strong></p>
<p>　　　　　　<strong>注:</strong> 为了提高效率，db.collection.bulkWrite，支持：insert update remove 同时也支持insertMany</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">db.mystudents.bulkWrite([</span><br><span class="line">&#123;insertOne:&#123;<span class="string">&quot;document&quot;</span>:&#123;<span class="string">&quot;_id&quot;</span>:<span class="number">100</span>,<span class="string">&quot;name&quot;</span>:<span class="string">&quot;Tom&quot;</span>,<span class="string">&quot;age&quot;</span>:<span class="number">25</span>&#125;&#125;&#125;,</span><br><span class="line">&#123;insertOne:&#123;<span class="string">&quot;document&quot;</span>:&#123;<span class="string">&quot;_id&quot;</span>:<span class="number">101</span>,<span class="string">&quot;name&quot;</span>:<span class="string">&quot;Mary&quot;</span>,<span class="string">&quot;age&quot;</span>:<span class="number">24</span>&#125;&#125;&#125;,</span><br><span class="line">&#123;updateOne:&#123;<span class="string">&quot;filter&quot;</span>:&#123;<span class="string">&quot;_id&quot;</span>:<span class="number">100</span>&#125;,<span class="string">&quot;update&quot;</span>:&#123;$<span class="built_in">set</span>:&#123;<span class="string">&quot;name&quot;</span>:<span class="string">&quot;Tom123&quot;</span>&#125;&#125;&#125;&#125;</span><br><span class="line">]);</span><br></pre></td></tr></table></figure>

<h3 id="1-2-MongoDB查询操作"><a href="#1-2-MongoDB查询操作" class="headerlink" title="1.2 MongoDB查询操作"></a>1.2 MongoDB查询操作</h3><p>　　<strong>1、基本查询</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">db.emp.insert(</span><br><span class="line">[</span><br><span class="line">&#123;_id:<span class="number">7369</span>,ename:<span class="string">&#x27;SMITH&#x27;</span> ,job:<span class="string">&#x27;CLERK&#x27;</span>    ,mgr:<span class="number">7902</span>,hiredate:<span class="string">&#x27;17-12-80&#x27;</span>,sal:<span class="number">800</span>,comm:<span class="number">0</span>,deptno:<span class="number">20</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7499</span>,ename:<span class="string">&#x27;ALLEN&#x27;</span> ,job:<span class="string">&#x27;SALESMAN&#x27;</span> ,mgr:<span class="number">7698</span>,hiredate:<span class="string">&#x27;20-02-81&#x27;</span>,sal:<span class="number">1600</span>,comm:<span class="number">300</span> ,deptno:<span class="number">30</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7521</span>,ename:<span class="string">&#x27;WARD&#x27;</span>  ,job:<span class="string">&#x27;SALESMAN&#x27;</span> ,mgr:<span class="number">7698</span>,hiredate:<span class="string">&#x27;22-02-81&#x27;</span>,sal:<span class="number">1250</span>,comm:<span class="number">500</span> ,deptno:<span class="number">30</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7566</span>,ename:<span class="string">&#x27;JONES&#x27;</span> ,job:<span class="string">&#x27;MANAGER&#x27;</span>  ,mgr:<span class="number">7839</span>,hiredate:<span class="string">&#x27;02-04-81&#x27;</span>,sal:<span class="number">2975</span>,comm:<span class="number">0</span>,deptno:<span class="number">20</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7654</span>,ename:<span class="string">&#x27;MARTIN&#x27;</span>,job:<span class="string">&#x27;SALESMAN&#x27;</span> ,mgr:<span class="number">7698</span>,hiredate:<span class="string">&#x27;28-09-81&#x27;</span>,sal:<span class="number">1250</span>,comm:<span class="number">1400</span>,deptno:<span class="number">30</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7698</span>,ename:<span class="string">&#x27;BLAKE&#x27;</span> ,job:<span class="string">&#x27;MANAGER&#x27;</span>  ,mgr:<span class="number">7839</span>,hiredate:<span class="string">&#x27;01-05-81&#x27;</span>,sal:<span class="number">2850</span>,comm:<span class="number">0</span>,deptno:<span class="number">30</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7782</span>,ename:<span class="string">&#x27;CLARK&#x27;</span> ,job:<span class="string">&#x27;MANAGER&#x27;</span>  ,mgr:<span class="number">7839</span>,hiredate:<span class="string">&#x27;09-06-81&#x27;</span>,sal:<span class="number">2450</span>,comm:<span class="number">0</span>,deptno:<span class="number">10</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7788</span>,ename:<span class="string">&#x27;SCOTT&#x27;</span> ,job:<span class="string">&#x27;ANALYST&#x27;</span>  ,mgr:<span class="number">7566</span>,hiredate:<span class="string">&#x27;19-04-87&#x27;</span>,sal:<span class="number">3000</span>,comm:<span class="number">0</span>,deptno:<span class="number">20</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7839</span>,ename:<span class="string">&#x27;KING&#x27;</span>  ,job:<span class="string">&#x27;PRESIDENT&#x27;</span>,mgr:<span class="number">0</span>,hiredate:<span class="string">&#x27;17-11-81&#x27;</span>,sal:<span class="number">5000</span>,comm:<span class="number">0</span>,deptno:<span class="number">10</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7844</span>,ename:<span class="string">&#x27;TURNER&#x27;</span>,job:<span class="string">&#x27;SALESMAN&#x27;</span> ,mgr:<span class="number">7698</span>,hiredate:<span class="string">&#x27;08-09-81&#x27;</span>,sal:<span class="number">1500</span>,comm:<span class="number">0</span>,deptno:<span class="number">30</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7876</span>,ename:<span class="string">&#x27;ADAMS&#x27;</span> ,job:<span class="string">&#x27;CLERK&#x27;</span>    ,mgr:<span class="number">7788</span>,hiredate:<span class="string">&#x27;23-05-87&#x27;</span>,sal:<span class="number">1100</span>,comm:<span class="number">0</span>,deptno:<span class="number">20</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7900</span>,ename:<span class="string">&#x27;JAMES&#x27;</span> ,job:<span class="string">&#x27;CLERK&#x27;</span>    ,mgr:<span class="number">7698</span>,hiredate:<span class="string">&#x27;03-12-81&#x27;</span>,sal:<span class="number">950</span>,comm:<span class="number">0</span>,deptno:<span class="number">30</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7902</span>,ename:<span class="string">&#x27;FORD&#x27;</span>  ,job:<span class="string">&#x27;ANALYST&#x27;</span>  ,mgr:<span class="number">7566</span>,hiredate:<span class="string">&#x27;03-12-81&#x27;</span>,sal:<span class="number">3000</span>,comm:<span class="number">0</span>,deptno:<span class="number">20</span>&#125;,</span><br><span class="line">&#123;_id:<span class="number">7934</span>,ename:<span class="string">&#x27;MILLER&#x27;</span>,job:<span class="string">&#x27;CLERK&#x27;</span>    ,mgr:<span class="number">7782</span>,hiredate:<span class="string">&#x27;23-01-82&#x27;</span>,sal:<span class="number">1300</span>,comm:<span class="number">0</span>,deptno:<span class="number">10</span>&#125;</span><br><span class="line">]</span><br><span class="line">);</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1、查询所有的员工信息</span></span><br><span class="line">db.emp.find()</span><br><span class="line"></span><br><span class="line"><span class="comment">#2、查询职位值经理的员工</span></span><br><span class="line">db.emp.find(&#123;<span class="string">&quot;job&quot;</span>:<span class="string">&quot;MANAGER&quot;</span>&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">#3、操作符：$in和$or</span></span><br><span class="line"><span class="comment">#查询职位是MANAGER或者是CLERK员工信息</span></span><br><span class="line">db.emp.find(&#123;<span class="string">&quot;job&quot;</span>:&#123;$<span class="keyword">in</span>:[<span class="string">&quot;MANAGER&quot;</span>,<span class="string">&quot;CLERK&quot;</span>]&#125;&#125;)</span><br><span class="line">db.emp.find(&#123;$<span class="keyword">or</span>:[&#123;<span class="string">&quot;job&quot;</span>:<span class="string">&quot;MANAGER&quot;</span>&#125;,&#123;<span class="string">&quot;job&quot;</span>:<span class="string">&quot;CLERK&quot;</span>&#125;]&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">#4、查询10号部门工资大于2000的员工</span></span><br><span class="line">db.emp.find(&#123;<span class="string">&quot;sal&quot;</span>:&#123;$gt:<span class="number">2000</span>&#125;,<span class="string">&quot;deptno&quot;</span>:<span class="number">10</span>&#125;)</span><br></pre></td></tr></table></figure>



<p>　　<strong>2、查询嵌套文档</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">db.student2.insertMany([</span><br><span class="line">&#123;_id:<span class="string">&quot;stu0001&quot;</span>,name:<span class="string">&quot;Mary&quot;</span>,age:<span class="number">25</span>,grade:&#123;chinese:<span class="number">80</span>,math:<span class="number">85</span>,english:<span class="number">90</span>&#125;&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu0002&quot;</span>,name:<span class="string">&quot;Tom&quot;</span>,age:<span class="number">25</span>,grade:&#123;chinese:<span class="number">86</span>,math:<span class="number">82</span>,english:<span class="number">95</span>&#125;&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu0003&quot;</span>,name:<span class="string">&quot;Mike&quot;</span>,age:<span class="number">25</span>,grade:&#123;chinese:<span class="number">81</span>,math:<span class="number">90</span>,english:<span class="number">88</span>&#125;&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu0004&quot;</span>,name:<span class="string">&quot;Jerry&quot;</span>,age:<span class="number">25</span>,grade:&#123;chinese:<span class="number">95</span>,math:<span class="number">87</span>,english:<span class="number">89</span>&#125;&#125;</span><br><span class="line">])</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1、查询语文是81分，英语成绩是88分的文档</span></span><br><span class="line">db.student2.find(&#123;grade:&#123;chinese:81,english:88&#125;&#125;)   ---&gt; 得不到结果</span><br><span class="line"></span><br><span class="line"><span class="comment">#2、查询语文是81分，数学90分，英语成绩是88分的文档</span></span><br><span class="line">db.student2.find(&#123;grade:&#123;chinese:81,math:90,english:88&#125;&#125;)  ---&gt; 得到结果</span><br><span class="line"><span class="comment"># &#123; &quot;_id&quot; : &quot;stu0003&quot;, &quot;name&quot; : &quot;Mike&quot;, &quot;age&quot; : 25, &quot;grade&quot; : &#123; &quot;chinese&quot; : 81, &quot;math&quot; : 90, &quot;english&quot; : 88 &#125; &#125;</span></span><br><span class="line">小结：如果是相等查询，保证匹配所有的field，顺序也要一样</span><br><span class="line">    </span><br><span class="line"><span class="comment">#3、查询嵌套文档中的一个列：查询数学成绩是82分的文档</span></span><br><span class="line">db.student2.find(&#123;<span class="string">&quot;grade.math&quot;</span>:<span class="number">82</span>&#125;)</span><br><span class="line">    </span><br><span class="line"><span class="comment">#4、使用比较运算符：查询英语成绩大于88分文档</span></span><br><span class="line">db.student2.find(&#123;<span class="string">&quot;grade.english&quot;</span>:&#123;$gt:<span class="number">88</span>&#125;&#125;)</span><br><span class="line">    </span><br><span class="line"><span class="comment">#5、使用AND运算符：查询英语成绩大于88分，语文成绩大于85分的文档</span></span><br><span class="line">db.student2.find(&#123;<span class="string">&quot;grade.english&quot;</span>:&#123;$gt:<span class="number">88</span>&#125;,<span class="string">&quot;grade.chinese&quot;</span>:&#123;$gt:<span class="number">85</span>&#125;&#125;)</span><br></pre></td></tr></table></figure>

<p>　　<strong>3、查询数组文档</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">db.studentbook.insert([</span><br><span class="line">&#123;_id:<span class="string">&quot;stu001&quot;</span>,name:<span class="string">&quot;Tom&quot;</span>,books:[<span class="string">&quot;Hadoop&quot;</span>,<span class="string">&quot;Java&quot;</span>,<span class="string">&quot;NoSQL&quot;</span>]&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu002&quot;</span>,name:<span class="string">&quot;Mary&quot;</span>,books:[<span class="string">&quot;C++&quot;</span>,<span class="string">&quot;Java&quot;</span>,<span class="string">&quot;Oracle&quot;</span>]&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu003&quot;</span>,name:<span class="string">&quot;Mike&quot;</span>,books:[<span class="string">&quot;Java&quot;</span>,<span class="string">&quot;MySQL&quot;</span>,<span class="string">&quot;PHP&quot;</span>]&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu004&quot;</span>,name:<span class="string">&quot;Jerry&quot;</span>,books:[<span class="string">&quot;Hadoop&quot;</span>,<span class="string">&quot;Spark&quot;</span>,<span class="string">&quot;Java&quot;</span>]&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu005&quot;</span>,name:<span class="string">&quot;Jone&quot;</span>,books:[<span class="string">&quot;C&quot;</span>,<span class="string">&quot;Python&quot;</span>]&#125;</span><br><span class="line">])</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1、查询所有有Hadoop和Java的文档</span></span><br><span class="line">错误：db.studentbook.find(&#123;books:[&quot;Hadoop&quot;,&quot;Java&quot;]&#125;)  ---&gt; 没有结果</span><br><span class="line">正确：db.studentbook.find(&#123;books:&#123;$<span class="built_in">all</span>:[<span class="string">&quot;Hadoop&quot;</span>,<span class="string">&quot;Java&quot;</span>]&#125;&#125;)</span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : &quot;stu001&quot;, &quot;name&quot; : &quot;Tom&quot;, &quot;books&quot; : [ &quot;Hadoop&quot;, &quot;Java&quot;, &quot;NoSQL&quot; ] &#125;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : &quot;stu004&quot;, &quot;name&quot; : &quot;Jerry&quot;, &quot;books&quot; : [ &quot;Hadoop&quot;, &quot;Spark&quot;, &quot;Java&quot; ] &#125;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#2、根查询嵌套的文档一样，匹配每个元素，顺序也要一致</span></span><br><span class="line">db.studentbook.find(&#123;books:[<span class="string">&quot;Hadoop&quot;</span>,<span class="string">&quot;Java&quot;</span>,<span class="string">&quot;NoSQL&quot;</span>]&#125;)</span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : &quot;stu001&quot;, &quot;name&quot; : &quot;Tom&quot;, &quot;books&quot; : [ &quot;Hadoop&quot;, &quot;Java&quot;, &quot;NoSQL&quot; ] &#125;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br></pre></td></tr></table></figure>

<p>　　<strong>4、查询数组中嵌套的文档</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">db.studentbook1.insertMany([</span><br><span class="line">&#123;_id:<span class="string">&quot;stu001&quot;</span>,name:<span class="string">&quot;Tome&quot;</span>,books:[&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Hadoop&quot;</span>, quantity:<span class="number">2</span>&#125;,&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Java&quot;</span>, quantity:<span class="number">3</span>&#125;,&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;NoSQL&quot;</span>, quantity:<span class="number">4</span>&#125;]&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu002&quot;</span>,name:<span class="string">&quot;Mary&quot;</span>,books:[&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;C++&quot;</span>, quantity:<span class="number">4</span>&#125;,   &#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Java&quot;</span>, quantity:<span class="number">3</span>&#125;,&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Oracle&quot;</span>, quantity:<span class="number">5</span>&#125;]&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu003&quot;</span>,name:<span class="string">&quot;Mike&quot;</span>,books:[&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Java&quot;</span>, quantity:<span class="number">4</span>&#125;,  &#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;MySQL&quot;</span>, quantity:<span class="number">1</span>&#125;,&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;PHP&quot;</span>, quantity:<span class="number">1</span>&#125;]&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu004&quot;</span>,name:<span class="string">&quot;Jone&quot;</span>,books:[&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Hadoop&quot;</span>, quantity:<span class="number">3</span>&#125;,&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Spark&quot;</span>, quantity:<span class="number">2</span>&#125;,&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Java&quot;</span>, quantity:<span class="number">4</span>&#125;]&#125;,</span><br><span class="line">&#123;_id:<span class="string">&quot;stu005&quot;</span>,name:<span class="string">&quot;Jane&quot;</span>,books:[&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;C&quot;</span>, quantity:<span class="number">1</span>&#125;,     &#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Python&quot;</span>, quantity:<span class="number">5</span>&#125;]&#125;])</span><br></pre></td></tr></table></figure>



<p> <strong>查询数组中嵌套文档</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1、查询Java有4本的文档</span></span><br><span class="line">db.studentbook1.find(&#123;books:&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Java&quot;</span>,<span class="string">&quot;quantity&quot;</span>:<span class="number">4</span>&#125;&#125;)</span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">&#123;</span></span><br><span class="line"><span class="string">    &quot;_id&quot;: &quot;stu003&quot;,</span></span><br><span class="line"><span class="string">    &quot;name&quot;: &quot;Mike&quot;,</span></span><br><span class="line"><span class="string">    &quot;books&quot;: [&#123;</span></span><br><span class="line"><span class="string">        &quot;bookname&quot;: &quot;Java&quot;,</span></span><br><span class="line"><span class="string">        &quot;quantity&quot;: 4</span></span><br><span class="line"><span class="string">    &#125;, &#123;</span></span><br><span class="line"><span class="string">        &quot;bookname&quot;: &quot;MySQL&quot;,</span></span><br><span class="line"><span class="string">        &quot;quantity&quot;: 1</span></span><br><span class="line"><span class="string">    &#125;, &#123;</span></span><br><span class="line"><span class="string">        &quot;bookname&quot;: &quot;PHP&quot;,</span></span><br><span class="line"><span class="string">        &quot;quantity&quot;: 1</span></span><br><span class="line"><span class="string">    &#125;]</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#2、指定查询的条件：查询数组中第一个元素大于3本的文档</span></span><br><span class="line">db.studentbook1.find(&#123;<span class="string">&quot;books.0.quantity&quot;</span>:&#123;$gt:<span class="number">3</span>&#125;&#125;)</span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">&#123;</span></span><br><span class="line"><span class="string">    &quot;_id&quot;: &quot;stu002&quot;,</span></span><br><span class="line"><span class="string">    &quot;name&quot;: &quot;Mary&quot;,</span></span><br><span class="line"><span class="string">    &quot;books&quot;: [&#123;</span></span><br><span class="line"><span class="string">        &quot;bookname&quot;: &quot;C++&quot;,</span></span><br><span class="line"><span class="string">        &quot;quantity&quot;: 4</span></span><br><span class="line"><span class="string">    &#125;, &#123;</span></span><br><span class="line"><span class="string">        &quot;bookname&quot;: &quot;Java&quot;,</span></span><br><span class="line"><span class="string">        &quot;quantity&quot;: 3</span></span><br><span class="line"><span class="string">    &#125;, &#123;</span></span><br><span class="line"><span class="string">        &quot;bookname&quot;: &quot;Oracle&quot;,</span></span><br><span class="line"><span class="string">        &quot;quantity&quot;: 5</span></span><br><span class="line"><span class="string">    &#125;]</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line">                </span><br><span class="line"><span class="comment">#3、如果不知道field的位置: 查询文档中至少有一个quantity的值大于3</span></span><br><span class="line">db.studentbook1.find(&#123;<span class="string">&quot;books.quantity&quot;</span>:&#123;$gt:<span class="number">3</span>&#125;&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">#4、查询Java等于4本的文档</span></span><br><span class="line">db.studentbook1.find(&#123;<span class="string">&quot;books&quot;</span>:&#123;$elemMatch:&#123;<span class="string">&quot;bookname&quot;</span>:<span class="string">&quot;Java&quot;</span>,<span class="string">&quot;quantity&quot;</span>:<span class="number">4</span>&#125;&#125;&#125;)</span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">&#123;</span></span><br><span class="line"><span class="string">    &quot;_id&quot;: &quot;stu003&quot;,</span></span><br><span class="line"><span class="string">    &quot;name&quot;: &quot;Mike&quot;,</span></span><br><span class="line"><span class="string">    &quot;books&quot;: [&#123;</span></span><br><span class="line"><span class="string">        &quot;bookname&quot;: &quot;Java&quot;,</span></span><br><span class="line"><span class="string">        &quot;quantity&quot;: 4</span></span><br><span class="line"><span class="string">    &#125;, &#123;</span></span><br><span class="line"><span class="string">        &quot;bookname&quot;: &quot;MySQL&quot;,</span></span><br><span class="line"><span class="string">        &quot;quantity&quot;: 1</span></span><br><span class="line"><span class="string">    &#125;, &#123;</span></span><br><span class="line"><span class="string">        &quot;bookname&quot;: &quot;PHP&quot;,</span></span><br><span class="line"><span class="string">        &quot;quantity&quot;: 1</span></span><br><span class="line"><span class="string">    &#125;]</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br></pre></td></tr></table></figure>



<p>　　<strong>5、查询空值null或者缺失的列</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">db.student3.insertMany([</span><br><span class="line">   &#123; _id: <span class="number">1</span>,name:<span class="string">&quot;Tom&quot;</span>,age:null &#125;,</span><br><span class="line">   &#123; _id: <span class="number">2</span>,name:<span class="string">&quot;Mary&quot;</span>&#125;</span><br><span class="line">])</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1、查询值为null的文档</span></span><br><span class="line">db.student3.find(&#123;age:null&#125;)  ---&gt; 返回两条记录</span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : 1, &quot;name&quot; : &quot;Tom&quot;, &quot;age&quot; : null &#125;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : 2, &quot;name&quot; : &quot;Mary&quot; &#125;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#2、只返回null的记录：BSON表示null：10</span></span><br><span class="line">db.student3.find(&#123;<span class="string">&quot;age&quot;</span>:&#123;$<span class="built_in">type</span>:<span class="number">10</span>&#125;&#125;)</span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : 1, &quot;name&quot; : &quot;Tom&quot;, &quot;age&quot; : null &#125;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line">                </span><br><span class="line"><span class="comment">#3、检查是否缺失某个列</span></span><br><span class="line">db.student3.find(&#123;age:&#123;$exists:false&#125;&#125;)</span><br><span class="line">db.student3.find(&#123;age:&#123;$exists:true&#125;&#125;)</span><br></pre></td></tr></table></figure>





<p>　　<strong>6、使用游标</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1、定义游标</span></span><br><span class="line">var mycursor = db.emp.find()</span><br><span class="line">mycursor</span><br><span class="line"></span><br><span class="line"><span class="comment">#2、使用游标访问文档（打印json格式数据）</span></span><br><span class="line">var mycursor = db.emp.find()</span><br><span class="line"><span class="keyword">while</span>(mycursor.hasNext())&#123;</span><br><span class="line">printjson(mycursor.<span class="built_in">next</span>())</span><br><span class="line">&#125;    </span><br><span class="line"></span><br><span class="line"><span class="comment">#3、游标和数组</span></span><br><span class="line">var mycursor = db.emp.find()                       <span class="comment"># 定义一个游标</span></span><br><span class="line">var myarray = mycursor.toArray()                   <span class="comment"># 将查询结果转换成数组</span></span><br><span class="line">var mydoc = myarray[<span class="number">3</span>]                             <span class="comment"># 取出数组中第3条数据</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#4、分页操作</span></span><br><span class="line">第一页： limit表示查询过滤出前<span class="number">5</span>条数据</span><br><span class="line">var mycursor = db.emp.find().limit(<span class="number">5</span>)</span><br><span class="line">第二页： skip(<span class="number">5</span>)表示跳过多少条数据</span><br><span class="line">var mycursor = db.emp.find().limit(<span class="number">5</span>).skip(<span class="number">5</span>)</span><br></pre></td></tr></table></figure>

<h3 id="1-3-聚合操作：aggregation"><a href="#1-3-聚合操作：aggregation" class="headerlink" title="1.3 聚合操作：aggregation"></a>1.3 聚合操作：aggregation</h3><p>　　<strong>1、聚合操作说明</strong></p>
<p>　　　　　　1. Pipeline:速度快于MapReduce，单个的聚合操作耗费的内存不能超过20%，返回的结果集：限制在16M</p>
<p>　　　　　　2. MapReduce：多个Server上并行计算</p>
<p> 　<strong>2、Pipeline聚合操作</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1、$match和$project</span></span><br><span class="line">$match: 过滤进入PipeLine的数据</span><br><span class="line">$project:指定提取的列，其中： <span class="number">1</span>表示提取列  <span class="number">0</span>不提取</span><br><span class="line"><span class="comment">#查询部门id=10，只显示ename、sal、deptno</span></span><br><span class="line">db.emp.aggregate(</span><br><span class="line">&#123;$match:&#123;<span class="string">&quot;deptno&quot;</span>:&#123;$eq:<span class="number">10</span>&#125;&#125;&#125;,</span><br><span class="line">&#123;$project:&#123;<span class="string">&quot;ename&quot;</span>:<span class="number">1</span>,<span class="string">&quot;sal&quot;</span>:<span class="number">1</span>,<span class="string">&quot;deptno&quot;</span>:<span class="number">1</span>&#125;&#125;</span><br><span class="line">);    </span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : 7782, &quot;ename&quot; : &quot;CLARK&quot;, &quot;sal&quot; : 2450, &quot;deptno&quot; : 10 &#125;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : 7839, &quot;ename&quot; : &quot;KING&quot;, &quot;sal&quot; : 8000, &quot;deptno&quot; : 10 &#125;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : 7934, &quot;ename&quot; : &quot;MILLER&quot;, &quot;sal&quot; : 1300, &quot;deptno&quot; : 10 &#125;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br></pre></td></tr></table></figure>



<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">db.emp.aggregate(</span><br><span class="line">&#123;$project:&#123;<span class="string">&quot;sal&quot;</span>:<span class="number">1</span>,<span class="string">&quot;deptno&quot;</span>:<span class="number">1</span>&#125;&#125;,</span><br><span class="line">&#123;$group:&#123;<span class="string">&quot;_id&quot;</span>:<span class="string">&quot;$deptno&quot;</span>,salTotal:&#123;$<span class="built_in">sum</span>:<span class="string">&quot;$sal&quot;</span>&#125;&#125;&#125;</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : 10, &quot;salTotal&quot; : 11750 &#125;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : 30, &quot;salTotal&quot; : 9400 &#125;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : 20, &quot;salTotal&quot; : 10875 &#125;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br></pre></td></tr></table></figure>



<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#3、按照部门，不同的职位求工资总额</span></span><br><span class="line"><span class="comment">#select deptno,job,sum(sal) from emp group by deptno,job;</span></span><br><span class="line">db.emp.aggregate(</span><br><span class="line">&#123;$project:&#123;<span class="string">&quot;job&quot;</span>:<span class="number">1</span>,<span class="string">&quot;sal&quot;</span>:<span class="number">1</span>,<span class="string">&quot;deptno&quot;</span>:<span class="number">1</span>&#125;&#125;,</span><br><span class="line">&#123;$group:&#123;<span class="string">&quot;_id&quot;</span>:&#123;<span class="string">&quot;deptno&quot;</span>:<span class="string">&quot;$deptno&quot;</span>,<span class="string">&quot;job&quot;</span>:<span class="string">&quot;$job&quot;</span>&#125;,salTotal:&#123;$<span class="built_in">sum</span>:<span class="string">&quot;$sal&quot;</span>&#125;&#125;&#125;</span><br><span class="line">);    </span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : &#123; &quot;deptno&quot; : 20, &quot;job&quot; : &quot;ANALYST&quot; &#125;, &quot;salTotal&quot; : 6000 &#125;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : &#123; &quot;deptno&quot; : 30, &quot;job&quot; : &quot;SALESMAN&quot; &#125;, &quot;salTotal&quot; : 5600 &#125;</span></span><br><span class="line"><span class="string">&#123; &quot;_id&quot; : &#123; &quot;deptno&quot; : 20, &quot;job&quot; : &quot;CLERK&quot; &#125;, &quot;salTotal&quot; : 1900 &#125;</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br></pre></td></tr></table></figure>






        </div>
        <div class="article-copyright">
            
    <blockquote>
        <p>
            版权声明：本文为「子曰无衣」的原创文章，博客内容遵循 署名-非商业性使用-相同方式共享 协议。<br>本文永久链接是：https://wangpdizhi.gitee.io/mhexo/2020/12/19/MongoDB/
        </p>
    </blockquote>


        </div>
    </article>
    

    <section id="toc-div" >
        <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#01%EF%BC%9AMongoDB%E5%9F%BA%E7%A1%80"><span class="toc-text">     01：MongoDB基础        </span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-MongoDB%E7%AE%80%E4%BB%8B"><span class="toc-text">1.1 MongoDB简介</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-MongoDB%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE"><span class="toc-text">1.2 MongoDB安装与配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-3-MongoDB%E7%9A%84%E4%BD%93%E7%B3%BB%E7%BB%93%E6%9E%84"><span class="toc-text">1.3 MongoDB的体系结构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-%E4%BD%BF%E7%94%A8mongo-shell"><span class="toc-text">1.4 使用mongo shell</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-5-MongoDB%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-text">1.5 MongoDB数据类型</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#02%EF%BC%9AMongoDB%E6%93%8D%E4%BD%9C"><span class="toc-text">     02：MongoDB操作        </span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-MongoDB-%E5%A2%9E%E5%8A%A0"><span class="toc-text">1.1 MongoDB 增加</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-MongoDB%E6%9F%A5%E8%AF%A2%E6%93%8D%E4%BD%9C"><span class="toc-text">1.2 MongoDB查询操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-3-%E8%81%9A%E5%90%88%E6%93%8D%E4%BD%9C%EF%BC%9Aaggregation"><span class="toc-text">1.3 聚合操作：aggregation</span></a></li></ol></li></ol></li></ol>
    </section>
    <section id="gohome" style="display: none;"><a>顶</a></section>

    <script>
        function get_top_by_link(link){
            var hnid = "#" + $(link).attr("data");
            if ($(hnid).length > 0){
                return $(hnid).offset().top;
            }else{
                return 0;
            }
        }
        //go to hn
        function gotohn(link){
            $("html,body").animate({scrollTop: get_top_by_link(link) }, 300);
        }
        //页面滚动
        function update(){
            var scrollH = $(window).scrollTop();
            if($(".toc-link")){
                $(".toc-link").each(function(i,link){
                    var mdHeight = get_top_by_link(link);
                    if(mdHeight <= scrollH + 40){
                        //高亮导航菜单
                        $('.toc-link').removeClass('on');
                        $(link).addClass('on');
                    }
                });
            }
            //返回顶部显隐
            if(scrollH < 200){
                $("#gohome").css("display","none");
            }else{
                $("#gohome").css("display","block");
            }
        }
        $(function(){
            //修复部分锚点从属关系
            if($("#toc-div >li").length > 0){
                $("#toc-div >li").appendTo($("#toc-div >ol:first"));
            }
            //返回顶部
            $('#gohome').click(function(){
                $("html,body").animate({scrollTop: 0}, 300);
                return false;
            })
            //遍历锚点
            $(".toc-link").each(function(i,link){
                $(link).attr("data",$(link).attr('href').substring(1));
                $(link).attr("href","javascript:void(0);");
                $(link).attr("onclick","gotohn(this);");
            })
            //绑定滚动事件
            $(window).bind('scroll', update);
            //初始化toc
            var first_toc = $(".toc-link")[0];
            var first_scroll = get_top_by_link(first_toc);
            var window_scroll = $(window).scrollTop();
            if(window_scroll <= first_scroll){
                $(first_toc).addClass('on');
            }
        })
    </script>

</section>
    </div>
    <footer>
    <div class="outer">
        <div class="inner">
            Powered by <a href="http://prowiki.demopage.icu/" target="_blank">ProWiki</a>
            &copy;2020 子曰无衣<br>
            <a target="_blank" rel="noopener" href="http://beian.miit.gov.cn/">冀ICP备00000000号</a>
        </div>
    </div>
</footer>

<script src="/mhexo/js/custom.js"></script>


    <script>onload_content();</script>

</body>
</html>
